/*
 *    This file is part of SSHTunneler.
 *
 *    Copyright 2009 Jean-Sebastien Gelinas <calestar@gmail.com>
 *
 *    SSHTunneler is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    SSHTunneler is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with SSHTunneler.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
package sshtunneler.toolsgui;

import sshtunneler.tools.Tool;

public class PanelToolEditProperty extends javax.swing.JPanel {
	private static final long serialVersionUID = -1520229672258867910L;
	String key;
	Tool t;

	public PanelToolEditProperty(Tool t, String key) {
		this.initComponents();
		this.t = t;
		this.key = key;
		this.txt_name.setText(key);
		this.txt_value.setText(t.getProperty(key));
		this.setVisible(true);
	}

	private void initComponents() {

		this.jPanel1 = new javax.swing.JPanel();
		this.jLabel1 = new javax.swing.JLabel();
		this.txt_name = new javax.swing.JTextField();
		this.jPanel2 = new javax.swing.JPanel();
		this.jLabel2 = new javax.swing.JLabel();
		this.txt_value = new javax.swing.JTextField();

		this.setName("Form");
		this.setLayout(new java.awt.BorderLayout(0, 15));

		this.jPanel1.setName("jPanel1");
		this.jPanel1.setLayout(new java.awt.BorderLayout());

		this.jLabel1.setText("Name");
		this.jLabel1.setName("jLabel1");
		this.jPanel1.add(this.jLabel1, java.awt.BorderLayout.NORTH);

		this.txt_name.setEditable(false);
		this.txt_name.setName("txt_name");
		this.jPanel1.add(this.txt_name, java.awt.BorderLayout.CENTER);

		this.add(this.jPanel1, java.awt.BorderLayout.NORTH);

		this.jPanel2.setName("jPanel2");
		this.jPanel2.setLayout(new java.awt.BorderLayout());

		this.jLabel2.setText("Value");
		this.jLabel2.setName("jLabel2");
		this.jPanel2.add(this.jLabel2, java.awt.BorderLayout.NORTH);

		this.txt_value.setName("txt_value");
		this.txt_value.addFocusListener(new java.awt.event.FocusAdapter() {
			@Override
			public void focusLost(java.awt.event.FocusEvent evt) {
				PanelToolEditProperty.this.txt_valueFocusLost(evt);
			}
		});
		this.jPanel2.add(this.txt_value, java.awt.BorderLayout.CENTER);

		this.add(this.jPanel2, java.awt.BorderLayout.CENTER);
	}

	private void txt_valueFocusLost(java.awt.event.FocusEvent evt) {
		String newValue = this.txt_value.getText();
		if (!(newValue.equals(this.t.getProperty(this.key)))) {
			this.t.setProperty(this.key, newValue);
		}
	}

	private javax.swing.JLabel jLabel1;
	private javax.swing.JLabel jLabel2;
	private javax.swing.JPanel jPanel1;
	private javax.swing.JPanel jPanel2;
	private javax.swing.JTextField txt_name;
	private javax.swing.JTextField txt_value;

}
